package edu.xaut.bookingsys.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.xaut.bookingsys.entity.InfoCourse;
import edu.xaut.bookingsys.mapper.InfoCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class InfoCourseService extends ServiceImpl<InfoCourseMapper, InfoCourse> {
    @Autowired
    private InfoTeacherService infoTeacherService;

    public List<InfoCourse> selectAll() {
        return getBaseMapper().selectList(Wrappers.emptyWrapper()).stream().map(v -> {
            v.setInfoTeacher(infoTeacherService.getById(v.getTeacherId()));
            return v;
        }).collect(Collectors.toList());
    }
    public List<InfoCourse> selectByTid(int tid) {
        return getBaseMapper().selectList(Wrappers.lambdaQuery(InfoCourse.class).eq(InfoCourse::getTeacherId,tid))
                .stream().map(v->{
                    v.setInfoTeacher(infoTeacherService.getById(v.getTeacherId()));
                    return v;
                }).collect(Collectors.toList());
    }
}
